package com.ibm.datamodel.exp;

import java.io.Serializable;
import java.util.Random;

import org.apache.commons.lang.SerializationUtils;
import org.apache.commons.math.stat.descriptive.rank.Max;

public class Utility {
	public static byte[] object2byte(Object o){
		byte[] data = SerializationUtils.serialize((Serializable) o);
		return data;
	}
	
	public static Object byte2ojbect(byte[] b){
		Object o = SerializationUtils.deserialize(b);
		return o;
	}
	
	static int Max = 0;
	
	public static int[] diemension(int x){
		int[] die = new int[x];
		Random r = new Random();
		for (int i = 0; i < die.length; i++) {
			double pro = r.nextDouble();
			if (pro < 0.5) {
				die[i] = 1;
			}else {
				die[i] = r.nextInt(1000) + 1;
				Max = die[i] > Max ? die[i] : Max;
			}
		}
		return die;
	}
	
	public static Double[][] generatedata(int[] demension){
		Double[][] tmp = new Double[demension.length][];
		double min = 1;
		double max = 100;
		Random r = new Random();
		for (int i = 0; i < demension.length; i++) {
			tmp[i] = new Double[demension[i]];
			for (int j = 0; j < demension[i]; j++) {
				tmp[i][j] = min + (max - min ) * r.nextDouble();
			}
		}
		return tmp;
	}
	
	public static void print(int[] die){
		String str = "";
		for (int i = 0; i < die.length; i++) {
			str += die[i] + " ";
		}
		System.out.println(str);
	}
	
	public static String print(double[] die){
		String str = "";
		for (int i = 0; i < die.length; i++) {
			str += die[i] + " ";
		}
		return str;
	}
	
	public static String print(Comparable[] die){
		String str = "";
		for (int i = 0; i < die.length; i++) {
			str += die[i] + " ";
		}
		return str;
	}
	
}
